﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;

namespace DAO
{
    public class CauHinhDAO
    {
        public List<shop_cauhinh> LayTatCaCauHinh()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var LCauHinh = from ch in EFashionDB.shop_cauhinhs
                           select ch;
            return LCauHinh.ToList();
        }

        public List<shop_cauhinh> LayCauHinhTheoID(int ID)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var CauHinh = from ch in EFashionDB.shop_cauhinhs
                          where ch.id == ID
                          select ch;
            return CauHinh.ToList();
        }

        public void ThemCauHinh(shop_cauhinh CauHinh)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.shop_cauhinhs.InsertOnSubmit(CauHinh);
            EFashionDB.SubmitChanges();

        }

        public void XoaCauHinhTheoID(int ID)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ListCauHinh = from ch in EFashionDB.shop_cauhinhs
                              where ch.id == ID
                              select ch;
            EFashionDB.shop_cauhinhs.DeleteAllOnSubmit(ListCauHinh);
            EFashionDB.SubmitChanges();
        }

        public void CapNhatGiaTriCauHinh(int ID, string GiaTri)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ListCauHinh = from ch in EFashionDB.shop_cauhinhs
                              where ch.id == ID
                              select ch;
            foreach (shop_cauhinh chinh in ListCauHinh)
            {
                chinh.GiaTri = GiaTri;
            }

            EFashionDB.SubmitChanges();

        }


 /////////////////////Code By NMCUONG////////////////////////////////////////

        
        public List<decimal> LayDSGiaTriKhuyenMai()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            List<decimal> Result = new List<decimal>();
            var ListCauHinh = from CH in EFashionDB.shop_cauhinhs
                          where CH.TenBien.Contains("KMTL")
                          select CH ;

            foreach (shop_cauhinh CauHinh in ListCauHinh)
            {
                Result.Add( Decimal.Parse(CauHinh.GiaTri));
            }

            Result.Sort();

            return Result;
        }

        public List<int> LayDSDieuKienKhuyenMai()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            List<int> Result = new List<int>();
            var ListCauHinh = from CH in EFashionDB.shop_cauhinhs
                              where CH.TenBien.Contains("DKKM")
                              select CH;

            foreach (shop_cauhinh CauHinh in ListCauHinh)
            {
                
                Result.Add(int.Parse(CauHinh.GiaTri));
            }

            Result.Sort();

            return Result;
        }

        public int LayDiemCongTichLuyBauChon()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_cauhinh TLBauChon = EFashionDB.shop_cauhinhs.Single(p => p.TenBien.Contains("TLBauChon"));
            return int.Parse(TLBauChon.GiaTri);
        }

        public int LayDiemCongTichLuyNhanXet()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_cauhinh TLBauChon = EFashionDB.shop_cauhinhs.Single(p => p.TenBien.Contains("TLNhanXet"));
            return int.Parse(TLBauChon.GiaTri);
        
        }
        public int LayDiemCongTichLuyMuaHang()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_cauhinh TLBauChon = EFashionDB.shop_cauhinhs.Single(p => p.TenBien.Contains("TLMuaSP"));
            return int.Parse(TLBauChon.GiaTri);
        
        }

    }
}
